package com.wlyuan.open.scanner.constant;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author lijing
 * 扫描类型 枚举
 */
@Getter
public enum ScannerCodeEnum {

    //公司租户
    COMPANY_TENANT("company_tenant", false, "公司租户", null),
    //司机租户
    DRIVER_TENANT("driver_tenant", false, "个体司机租户", null),
    //租户-增量同步时用
    TENANT("tenant", false, "租户", null),
    //用户
    USER("user", false, "用户", 8),
    //租户邀请关系
    TENANT_RELATION("tenant_relation", false, "租户邀请关系", 14),
    //司机
    DRIVER("driver", false, "司机", 10),
    //车辆
    VEHICLE("vehicle", false, "车辆", 11),
    //客户
    CUSTOMER("customer", false, "客户", 1),
    //线下承运方
    CARRIER_OFFLINE("carrier_offline", false, "线下承运方", null),
    //承运方
    CARRIER_ONLINE("carrier_online", false, "线上承运方", null),
    //承运方
    CARRIER("carrier", false, "承运方", null),
    //邀请关系
    RELATION("relation", false, "承运方邀请关系", 7),
    //物品
    GOODS("goods", false, "物品", 4),
    //收货方
    CONSIGNEE("consignee", false, "收货方", 3),
    //合同
    CONTRACT("contract", false, "合同", 12),
    //订单
    ORDER("order", false, "订单", 5),
    //运单
    TRANSPORT("transport", false, "运单", 6),
    //拼车单
    COMBINE("combine", false, "拼车单", 19),
    //合约
    TEMPLATE("template", false, "合约", 15),
    //报价
    QUOTATION("quotation", false, "报价", 16),
    //对账单
    BILL("bill", false, "对账单", 13),
    //收付款
    PAY("pay", false, "收付款", 17),
    TOP_EXTENSION("top_extension", false, "脱普扩展", 18),
    TRANSPORT_RELATION("transport_relation", false, "运单关系", 20),
    COMBINE_QUOTATION("combine_quotation", false, "合单报价", 21),
    ;

    /**
     * 值
     */
    private String val;
    /**
     * 是否开启
     */
    private boolean open;
    /**
     * 名称
     */
    private String name;

    private Integer sourceClass;

    ScannerCodeEnum(String val, boolean open, String name, Integer sourceClass) {
        this.open = open;
        this.val = val;
        this.name = name;
        this.sourceClass = sourceClass;
    }

    private static final Map<String, ScannerCodeEnum> MAP = Arrays.asList(ScannerCodeEnum.values()).stream().collect(Collectors.toMap(ScannerCodeEnum::getName, Function.identity()));

    private static final Map<Integer, ScannerCodeEnum> MAP_SOURCE_CLASS = Arrays.asList(ScannerCodeEnum.values()).stream().filter(x -> x.getSourceClass() != null).collect(Collectors.toMap(ScannerCodeEnum::getSourceClass, Function.identity()));

    public static ScannerCodeEnum fromName(String name) {
        return Optional.ofNullable(MAP.get(name)).orElse(null);
    }

    public static ScannerCodeEnum fromSourceClass(Integer sourceClass) {
        return Optional.ofNullable(MAP_SOURCE_CLASS.get(sourceClass)).orElse(null);
    }

}
